/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.view;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import vical.action.*;
import vical.controller.EntryController;
import vical.model.Internationalization;

/**
 * This is the main menu of the application.
 * 
 * @author Can
 * @author Pooya
 */
public class MenuBar extends JMenuBar {

    private JMenu fileMenu;
    private JMenu editMenu;
    private JMenu viewMenu;
    private JMenu custMenu;
    private JMenu helpMenu;
    private JMenu changeLang;
    private JMenuItem addTaskItem;
    private JMenuItem cutItem;
    private JMenuItem copyItem;
    private JMenuItem pasteItem;
    private JRadioButtonMenuItem mvItem; // month view
    private JRadioButtonMenuItem wvItem; // week view
    private JRadioButtonMenuItem dvItem; // day view
    private JRadioButtonMenuItem lvItem; // list view
    private JMenuItem settingItem;
    private JMenuItem lang_en;
    private JMenuItem lang_sv;
    private JMenuItem aboutItem;
    private JMenuItem howToUseItem;

    /**
     * Create and initialize an instance.
     */
    public MenuBar(MainWindow mainWindow) {

        /* Create menus */
        fileMenu = new JMenu(Internationalization.getString("fileMenu"));
        fileMenu.setMnemonic(Internationalization.getMnemonic("mnemonics_menu_file"));
        editMenu = new JMenu(Internationalization.getString("editMenu"));
        editMenu.setMnemonic(Internationalization.getMnemonic("mnemonics_menu_edit"));
        viewMenu = new JMenu(Internationalization.getString("viewMenu"));
        viewMenu.setMnemonic(Internationalization.getMnemonic("mnemonics_menu_view"));
        custMenu = new JMenu(Internationalization.getString("custMenu"));
        helpMenu = new JMenu(Internationalization.getString("helpMenu"));
        helpMenu.setMnemonic(Internationalization.getMnemonic("mnemonics_menu_help"));

        // Submenu for internationalization under customize menu
        changeLang = new JMenu(Internationalization.getString("changeLang"));
        changeLang.setMnemonic(Internationalization.getMnemonic("mnemonics_menu_language"));

        /* Create and set text of men items */
        // File menu
        addTaskItem = new JMenuItem(new EntryDialogAction(mainWindow));
        addTaskItem.setText(Internationalization.getString("add"));

        // Edit menu
        cutItem = new JMenuItem(new CutAction());
        cutItem.setText(Internationalization.getString("cut"));
        copyItem = new JMenuItem(new CopyAction());
        copyItem.setText(Internationalization.getString("copy"));
        pasteItem = new JMenuItem(new PasteAction());
        pasteItem.setText(Internationalization.getString("paste"));

        // View menu. There are 4 different views.
        ButtonGroup group = new ButtonGroup();

        mvItem = new JRadioButtonMenuItem(new MonthViewAction(mainWindow.getViewPanel()));
        group.add(mvItem);
        mvItem.setSelected(true);
        wvItem = new JRadioButtonMenuItem(new WeekViewAction(mainWindow.getViewPanel()));
        group.add(wvItem);
        dvItem = new JRadioButtonMenuItem(new DayViewAction(mainWindow.getViewPanel()));
        group.add(dvItem);
        lvItem = new JRadioButtonMenuItem(new ListViewAction(mainWindow.getViewPanel()));
        group.add(lvItem);

        // Customize menu
        lang_en = new JMenuItem(new ToEnglishAction(mainWindow));
        lang_sv = new JMenuItem(new ToSwedishAction(mainWindow));
        //     metal = new JMenuItem(new ToMetalThemeAction());
        settingItem = new JMenuItem(new SettingAction());


        // Help menu
        aboutItem = new JMenuItem(new AboutAction());
        howToUseItem = new JMenuItem(new HowToUseAction(mainWindow));

        /* Add items to menus */
        fileMenu.add(addTaskItem);
        fileMenu.add(new ExitAction(mainWindow));

        // added by Can
        editMenu.add(new UndoAction(EntryController.getUndoManager(), mainWindow));
        editMenu.add(new RedoAction(EntryController.getUndoManager(), mainWindow));

        viewMenu.add(mvItem);
        viewMenu.add(wvItem);
        viewMenu.add(dvItem);
        viewMenu.add(lvItem);

        changeLang.add(lang_en);
        changeLang.add(lang_sv);
        custMenu.add(changeLang);
        //custMenu.add(settingItem);

        helpMenu.add(aboutItem);
        helpMenu.add(howToUseItem);

        /* Add menus to MenuBar */
        add(fileMenu);
        add(editMenu);
        add(viewMenu);
        //add(custMenu);
        add(changeLang);
        add(helpMenu);
    }
}
